class Enyara extends xTeamGame;

var SquadAI squad;
var bool bMatchStarted;
var int currentSoldiers;
var() int Soldiers;
var() int Scientists;

function PostBeginPlay()
{
  super.PostBeginPlay();

  InitialBots = Soldiers + Scientists;
  bBalanceTeams = false;
}

function UnrealTeamInfo GetBotTeam(optional int TeamBots)
{
    return Teams[1];
}

function byte PickTeam(byte num, Controller C)
{
    return 0;
}

static event bool AcceptPlayInfoProperty(string PropertyName)
{
 if ( (PropertyName == "bBalanceTeams")
  || (PropertyName == "bPlayersBalanceTeams")
  || (PropertyName == "GoalScore") )
  return false;

 return Super.AcceptPlayInfoProperty(PropertyName);
}

function Bot SpawnBot(optional string botName)
{
 local Bot newBot;
 local RosterEntry Chosen;
 local UnrealTeamInfo botTeam;

 botTeam = GetBotTeam();
 Chosen = botTeam.ChooseBotClass(botName);

 if ((Soldiers - currentSoldiers) > 0 && InitialBots > Soldiers) {
   Chosen.PawnClass = class'Enyara.EnferiPawn';
   Chosen.PawnClassName = "Enyara.EnferiPawn";

   NewBot = Spawn(class'Enyara.EnferiController');//Chosen.PawnClass.default.ControllerClass));
   currentSoldiers++;
 } else {
   log("Spawned all soldiers, now spawning scientists"$Scientists);
   log("Soldiers"$Soldiers);
   Chosen.PawnClass = class'Enyara.ScientistPawn';
   Chosen.PawnClassName = "Enyara.ScientistPawn";

   NewBot = Spawn(class'Enyara.ScientistController');
 }

 if (NewBot != none) {
    InitializeBot(NewBot, BotTeam, Chosen);
 }

 return NewBot;
}

/* FindPlayerStart()
returns the 'best' player start for this player to start from.
*/
function NavigationPoint FindPlayerStart(Controller Player, optional byte InTeam, optional string incomingName)
{
  local NavigationPoint Best;
  local ScientistStart ps;

  if ( (Player != None) && (Player.StartSpot != None) )
    LastPlayerStartSpot = Player.StartSpot;

  Best = Super.FindPlayerStart(Player, InTeam, incomingName );

  if ( Player != none && Player.IsA('ScientistController') ) {
    foreach AllActors(class'ScientistStart', ps) {
        if (ps.Tag != 'ScientistSpawnUsed') {
          Best = ps;
          Best.Tag = 'ScientistSpawnUsed';
          break;
        }
    }
  }

  if ( !Player.IsA('ScientistController') && Best.IsA('ScientistStart'))  {
    while (!Best.IsA('ScientistStart'))
      Best = Super.FindPlayerStart(Player, InTeam, incomingName );
  }

  if ( Best != None )
    LastStartSpot = Best;

  return Best;
}

function Killed( Controller Killer, Controller Killed, Pawn KilledPawn, class<DamageType> damageType )
{
}

//
// Restart a player.
//
function RestartPlayer( Controller aPlayer )
{
    //To keep bots from respawning
    if (!bMatchStarted || EnyaraPlayerController(aPlayer) != none)
      super.RestartPlayer(aPlayer);
    else
      return;

    if (EnyaraPlayerController(aPlayer) != none) {
      EnyaraPlayerController(aPlayer).Mana = 100;
      EnyaraPlayerController(aPlayer).bInvulnToStun = false;
      EnyaraPlayerController(aPlayer).bAlreadyStunned = false;
      EnyaraPlayerController(aPlayer).GotoState('PlayerMousing');
    }
}

//
// Start the match
function StartMatch()
{
  super.StartMatch();

  //To keep bots from respawning
  bMatchStarted = true;
}

defaultproperties
{
     DefaultPlayerClassName="Enyara.EnyaraPawn"
     PlayerControllerClassName="Enyara.EnyaraPlayerController"
     ScoreBoardType="Enyara.EnyaraScoreBoard"
     HUDType="Enyara.HUDEnyara"
     MapPrefix="EY"
     BeaconName="EY"
     GameName="Enyara"
     bSpawnInTeamArea=true
     bBalanceTeams=false
     bQuickStart=true
     currentSoldiers=0
     Soldiers=7
     Scientists=2
}
